package ch.subgate.pongwars;

import android.content.Context;
import android.view.MotionEvent;

/**
 * Created by sam on 28.01.2015.
 */
public class GameContextMP extends GameContext {
    public GameContextMP(Context context, float volume) {
        super(context, volume);
    } // Constructor

    @Override
    public void initGameObjects(float paddleSize, boolean isServer) {
        // Instantiate game objects
        ball = new Ball(Constants.DIRECTION_BLUE_BEGINS);
        playerRed = new HumanPlayer(true, paddleSize);
        playerBlue = new HumanPlayer(false, paddleSize);
    } // initGameObjects

    @Override
    public void handleInput(int action, float diX, float diY) {
        if (mIsOn) {
            boolean down = true;
            if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) {
                down = false;
            } // if

            if (diY < (0.5f * Constants.DIC_BATTLEFIELD_HEIGHT)) {
                ((HumanPlayer)playerRed).setX(diX);
                ((HumanPlayer)playerRed).setIsCharging(!down);
            } else {
                ((HumanPlayer)playerBlue).setX(diX);
                ((HumanPlayer)playerBlue).setIsCharging(!down);
            } // if
        } else {
            if (diX > Constants.MESSAGE_LEFT
                    && diX < Constants.MESSAGE_RIGHT
                    && diY > Constants.MESSAGE_TOP
                    && diY < Constants.MESSAGE_BOTTOM) {
                mIsOn = true;
                // Initiate time measurement
                mLastFrame = System.nanoTime();
                mDeltaTime = 0.0f;
            } // if
        } // if
    } // handleInput

} // GameContextMP
